package org.jeecg.modules.bigdataanalysis.gasanalysis.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.aspect.annotation.AutoLog;
import org.jeecg.common.system.base.controller.JeecgController;
import org.jeecg.common.system.query.QueryGenerator;
import org.jeecg.modules.bigdataanalysis.wateranalysis.vo.RqAnalysisVo;
import org.jeecg.modules.bigdataanalysis.wateranalysis.vo.WsummaryAnalysisVo;
import org.jeecg.modules.earlywarning.information.entity.EwInformation;
import org.jeecg.modules.earlywarning.information.service.IEwInformationService;
import org.jeecg.modules.earlywarning.rules.entity.EwRules;
import org.jeecg.modules.earlywarning.rules.service.IEwRulesService;
import org.jeecg.modules.equipment.gasmeter.util.BulletUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Description: 燃气能源分析
 * @Author: 贾送兵
 * @Date:   2021-11-30
 * @Version: V1.0
 */
@Api(tags="大数据分析")
@RestController
@RequestMapping("/gasAnalysis")
@Slf4j
public class GasAnalysisController extends JeecgController<EwRules, IEwRulesService> {
	@Autowired
	private IEwInformationService ewInformationService;//预警


	@AutoLog(value = "燃气能耗分析")
	@ApiOperation(value="燃气能耗分析", notes="燃气能耗分析")
	@GetMapping(value = "/quere")
	public Result<?> queryeBycode(HttpServletRequest req, EwInformation ewInformation,@RequestParam(name = "warningTime_begin") String warningTimeBegin,
								  @RequestParam(name = "warningTime_end") String warningTimeEnd) {

		//存入租户id
		ewInformation.setTenantId(BulletUtil.getTenantId(req));
		//查询条件
		QueryWrapper<EwInformation> queryWrapper = QueryGenerator.initQueryWrapper(ewInformation, req.getParameterMap());

		//根据租户id及查询条件查询预警信息
		List<EwInformation> list = ewInformationService.list(queryWrapper);

		List<WsummaryAnalysisVo> sscList = new ArrayList<>();
		List<WsummaryAnalysisVo> tlcList = new ArrayList<>();
		List<WsummaryAnalysisVo> tzcList = new ArrayList<>();
		for (int i = 1; i < 5; i++) {
			for (int j = 1; j < 8; j++) {

				WsummaryAnalysisVo svo = new WsummaryAnalysisVo();
				svo.setDate("2021-10-"+j);//日期
				svo.setTotalCost("1000"+j);//总计费用
				svo.setEnergyNum("1000"+j);//能源使用量
				svo.setYieldNum("1000"+j);//产量
				svo.setAverageCost("1"+j);//费用均耗
				svo.setAverageEnergy("0.001"+j);//能源均耗
				svo.setTbNum("10.5%");//同比
				if((j&1)==1){
					svo.setState("1");//1是上涨，2是下跌
				}else{
					svo.setState("2");//1是上涨，2是下跌
				}
				if (i==1){sscList.add(svo);}
				if (i==2){tlcList.add(svo);}
				if (i==3){tzcList.add(svo);}
			}
		}

		//组装挡板数据
		Map<String,Object> map = new HashMap<>();
		map.put("rqNum","0.00098m³");//燃气消耗
		map.put("tzcNum","98000m³");//屠宰厂用量
		map.put("tlcNum","97000m³");//调理厂用量
		map.put("sscNum","96000m³");//熟食厂用量
		map.put("yjList",list);//预警信息
		map.put("sscList",sscList);//熟食厂分析
		map.put("tlcList",tlcList);//调理厂分析
		map.put("tzcList",tzcList);//屠宰厂分析

		return  Result.OK(map);
	}




}
